<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>权限管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport"
    content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../../layuiadmin/modules/dtree/dtree.css">
  <link rel="stylesheet" href="../../../layuiadmin/modules/dtree/font/dtreefont.css">
</head>

<body>
  <div class="layui-form" lay-filter="layuiadmin-form-privilege" id="layuiadmin-form-privilege"
    style="padding: 20px 30px 0 0;">
    <input type="hidden" name="mpid" value="">
    <div class="layui-form-item">
      <label class="layui-form-label">权限名称</label>
      <div class="layui-input-block">
        <input type='text' name='pmName' lay-verify="required" placeholder="权限名" class="layui-input" value="">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">权限code</label>
      <div class="layui-input-block">
        <input type='text' name='pmCode' lay-verify="required" placeholder="code" class="layui-input" value="">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">权限描述</label>
      <div class="layui-input-block">
        <input type='text' name='pmComment' lay-verify="required" placeholder="描述" class="layui-input" value="">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">所属页面</label>
      <div class="layui-input-block">
        <ul id="menu_tree" class="dtree" data-id="0"></ul>
      </div>
    </div>
    <div class="layui-form-item layui-hide">
      <button class="layui-btn" lay-submit lay-filter="user-privilege-submit" id="user-privilege-submit">提交</button>
    </div>
  </div>

  <script src="../../../layuiadmin/layui/layui.js"></script>
  <script>
    layui.config({
      base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
      index: 'lib/index' //主入口模块
      , my_send: '../myModules/my_send'
      , dtree: 'dtree/dtree'
    }).use(['index', 'form', 'dtree', 'my_send'], function () {
      var $ = layui.$
        , form = layui.form
        , dtree = layui.dtree
        , my_send = layui.my_send
        , http_proxy = layui.http_proxy;

      var params = location.search;

      if (params && params !== '') {
        var mpid = params.substr(params.indexOf('=') + 1);

        my_send({
          url: '/privilege/getPrivilegeByMpid'
          , type: 'post'
          , data: { 'mpid': mpid }
          , success: function (obj) {
            obj.rows[0];
            $('#layuiadmin-form-privilege input').eq(0).val(obj.rows[0].mpid);
            $('#layuiadmin-form-privilege input').eq(1).val(obj.rows[0].pmName);
            $('#layuiadmin-form-privilege input').eq(2).val(obj.rows[0].pmCode);
            $('#layuiadmin-form-privilege input').eq(3).val(obj.rows[0].pmComment);

            dtree.renderSelect({
              elem: '#menu_tree'
              , width: '100%'
              , url: http_proxy('/menu/getMenuResources')
              , selectTips: '选择当前权限的所属页面'
              , dataStyle: "layuiStyle"  //使用layui风格的数据格式
              , dataFormat: "list"  //配置data的风格为list
              , selectCardHeight: "150"
              , request: {
                limit: 1000
              }
              , done: function () {
                dtree.dataInit("menu_tree", obj.rows[0].parentId);
                var selectParam = dtree.selectVal("menu_tree");
              }
              , response: {
                statusCode: 0, //返回码（必填）
                rootName: 'rows',
                treeId: "mpid", //节点ID（必填）
                parentId: "parentId", //父节点ID（必填）
                title: "pmName", //节点名称（必填）
              }
            })
          }
        })
      } else {
        dtree.renderSelect({
          elem: '#menu_tree'
          , width: '100%'
          , url: http_proxy('/menu/getMenuResources')
          , selectTips: '选择当前权限的所属页面'
          , dataStyle: "layuiStyle"  //使用layui风格的数据格式
          , dataFormat: "list"  //配置data的风格为list
          , selectCardHeight: "150"
          , request: {
            limit: 1000
          }
          , response: {
            statusCode: 0, //返回码（必填）
            rootName: 'rows',
            treeId: "mpid", //节点ID（必填）
            parentId: "parentId", //父节点ID（必填）
            title: "pmName", //节点名称（必填）
          }
        })
      }
    })
  </script>
</body>

</html>